Passed
Branch master (9a7ed1)
by Rafael S.
01:20
created

endianess.js ➔ describe(ꞌlittle endiand and big endianꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 101

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 101
rs 8.2857

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
2
var assert = require('assert');
3
4
describe('little endiand and big endian', function() {
5
    
6
    let byteData = require('../../index.js');
7
8
    // 16-bit
9
    it('should turn 2 16-bit unsigned ints to 2 bytes BE (0s)', function() {
10
        assert.deepEqual(byteData.toBytes([0, 0], 16, {"base": 10, "be": true}),
11
            [0, 0, 0, 0]);
12
    });
13
    it('should turn 2 16-bit unsigned ints to 2 bytes LE (1s)', function() {
14
        assert.deepEqual(byteData.toBytes([1, 1], 16, {"base": 10, "be": false}),
15
            [1, 0, 1, 0]);
16
    });
17
    it('should turn 2 16-bit unsigned ints to 2 bytes BE (1s)', function() {
18
        assert.deepEqual(byteData.toBytes([1, 1], 16, {"base": 10, "be": true}),
19
            [0, 1, 0, 1]);
20
    });
21
22
    // 24-bit
23
    it('should turn 2 24-bit unsigned ints to 6 bytes BE (0s)', function() {
24
        assert.deepEqual(byteData.toBytes([0, 0], 24, {"base": 10, "be": true}),
25
            [0, 0, 0, 0, 0, 0]);
26
    });
27
    it('should turn 2 24-bit unsigned ints to 6 bytes LE (1s)', function() {
28
        assert.deepEqual(byteData.toBytes([1, 1], 24, {"base": 10, "be": false}),
29
            [1, 0, 0, 1, 0, 0]);
30
    });
31
    it('should turn 2 24-bit unsigned ints to 6 bytes BE (1s)', function() {
32
        assert.deepEqual(byteData.toBytes([1, 1], 24, {"base": 10, "be": true}),
33
            [0, 0, 1, 0, 0, 1]);
34
    });
35
    it('should turn 2 24-bit unsigned ints to 6 bytes BE (max range)', function() {
36
        assert.deepEqual(byteData.toBytes([-8388608, 8388607], 24, {"base": 16, "be": true}),
37
            ["80","00","00", "7f", "ff", "ff"]);
38
    });
39
    it('should turn 2 24-bit unsigned ints to 6 bytes BE', function() {
40
        assert.deepEqual(byteData.toBytes([-8388608, 1, 8388607], 24, {"base": 16, "be": true}),
41
            ["80","00","00" , "00","00","01", "7f", "ff", "ff"]);
42
    });
43
44
    // 32-bit
45
    it('should turn 2 32-bit unsigned ints to 8 bytes BE (0s)', function() {
46
        assert.deepEqual(byteData.toBytes([0, 0], 32, {"base": 10, "be": true}),
47
            [0, 0, 0, 0, 0, 0, 0, 0]);
48
    });
49
    it('should turn 2 32-bit unsigned ints to 8 bytes LE (1s)', function() {
50
        assert.deepEqual(byteData.toBytes([1, 1], 32, {"base": 10, "be": false}),
51
            [1, 0, 0, 0, 1, 0, 0, 0]);
52
    });
53
    it('should turn 2 32-bit unsigned ints to 8 bytes BE (1s)', function() {
54
        assert.deepEqual(byteData.toBytes([1, 1], 32, {"base": 10, "be": true}),
55
            [0, 0, 0, 1, 0,0, 0, 1]);
56
    });
57
58
    // 40-bit
59
    it('should turn 2 40-bit unsigned ints to 10 bytes BE (0s)', function() {
60
        assert.deepEqual(byteData.toBytes([0, 0], 40, {"base": 10, "be": true}),
61
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
62
    });
63
    it('should turn 2 40-bit unsigned ints to 10 bytes LE (1s)', function() {
64
        assert.deepEqual(byteData.toBytes([1, 1], 40, {"base": 10, "be": false}),
65
            [1, 0, 0, 0, 0, 1, 0, 0, 0, 0]);
66
    });
67
    it('should turn 2 40-bit unsigned ints to 10 bytes BE (1s)', function() {
68
        assert.deepEqual(byteData.toBytes([1, 1], 40, {"base": 10, "be": true}),
69
            [0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
70
    });
71
72
    // 48-bit
73
    it('should turn 2 48-bit unsigned ints to 12 bytes BE (0s)', function() {
74
        assert.deepEqual(byteData.toBytes([0, 0], 48, {"base": 10, "be": true}),
75
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
76
    });
77
    it('should turn 2 48-bit unsigned ints to 12 bytes LE (1s)', function() {
78
        assert.deepEqual(byteData.toBytes([1, 1], 48, {"base": 10, "be": false}),
79
            [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]);
80
    });
81
    it('should turn 2 48-bit unsigned ints to 12 bytes BE (1s)', function() {
82
        assert.deepEqual(byteData.toBytes([1, 1], 48, {"base": 10, "be": true}),
83
            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
84
    });
85
    it('should turn 1 48-bit unsigned ints to 6 bytes hex BE (120637438355317)', function() {
86
        assert.deepEqual(byteData.toBytes([120637438355317], 48, {"base": 16, "be": true}),
87
            ["6d", "b8", "17", "a8", "e7", "75"]);
88
            //["75", "e7", "a8", "17", "b8", "6d"]);  LE
89
    });
90
    it('should turn 1 48-bit unsigned ints to 6 bytes hex BE (120637438355317)', function() {
91
        assert.deepEqual(byteData.toBytes([120637438355317, 1, 1], 48, {"base": 16, "be": true}),
92
            ["6d", "b8", "17", "a8", "e7", "75", 
93
            "00", "00", "00", "00", "00", "01", 
94
            "00", "00", "00", "00", "00", "01"]);
95
    });
96
97
    // 64-bit
98
    it('should turn 1 64-bit float to 8 bytes BE (pi)', function() {
99
        assert.deepEqual(byteData.toBytes([3.141592653589793], 64, {"base": 10, "be": true}),
100
            [64, 9, 33, 251, 84, 68, 45, 24]);
101
            //[24,45,68,84,251,33,9,64]); LE
102
    });
103
104
});
105